package com.spkj.srb.easyexcel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.spkj.srb.easyexcel.pojo.dto.ExcelStudentDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * @author spkj
 * @create 2022-06-15 20:57
 */
public class ExcelStudentListener extends AnalysisEventListener<ExcelStudentDTO> {
    List<ExcelStudentDTO> list = new ArrayList<>();
    @Override
    public void invoke(ExcelStudentDTO excelStudentDTO, AnalysisContext analysisContext) {

        list.add(excelStudentDTO);
        if (list.size() >= 17){
            System.out.println("每读取17条数据，执行一次"+list.size());
            list.clear();
        }
//        System.out.println("读取一条数据：" + excelStudentDTO.getName());
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("当所有数据读取完成后，收尾执行 " + list.size());
    }
}
